<template>
	<view class="content">
		<view class="swiper-block">
				<image src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/home/jq-erq/banner.png" class="img"></image>
		</view>
		<view class="menu-block">
			<view class="title">
				请填写基本信息
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">真实姓名</view>
				</view>
				<view class="form-content">
					<input v-model="form.realName" maxlength="10" type="text" placeholder-class="inputPlaceholder"
						placeholder="请填写姓名" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">手机号码</view>
				</view>
				<view class="form-content">
					<input v-model="form.phone" maxlength="11" type="number" placeholder-class="inputPlaceholder"
						placeholder="请填写手机号码" class="form-ctrl"/>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">培训意向</view>
				</view>
				<view class="form-content">
					<input v-model="form.content" maxlength="100" type="text" placeholder="请简单描述一下你的培训意向"
						placeholder-class="inputPlaceholder" class="form-ctrl"/>
				</view>
			</view>
		</view>
		<view class="step" @click="handleSave">
			提交
		</view>
	</view>
</template>

<script>
	import {
		userAddTrainIntentionApi
	} from '@/api/train.js';
	import {
		validate
	} from '@/util/validate.js'
	export default {
		data() {
			return {
				form: {
					realName: '',
					phone: '',
					content: ''
				},
				type:1,
				tabActive: 0,
				labelIndex: 0,
				rules: {
					realName: {
						name: '真实姓名',
						required: true
					},
					phone: {
						name: '手机号',
						required: true,
						validator: function(value, form, callback) {
							if (!/^1[3-9][0-9]{9}$/.test(value)) {
								callback('请输入正确的手机号')
							}
							callback();
						}
					},
					content: {
						name: '培训意向',
						required: true
					},
				},
				id: null,
			}
		},
		methods: {
			bindType(e) {
				this.labelIndex = e.detail.value
			},
			bindActive(index) {
				this.tabActive = index
				if (this.tabActive == 0) {
				}
				if (this.tabActive == 2) {
				}
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			handleSave() {
				let form = JSON.parse(JSON.stringify(this.form));
				form.realName = this.form.realName
				form.phone = this.form.phone
				form.content = this.form.content
				if (validate(form, this.rules)) {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					userAddTrainIntentionApi(form).then((res) => {
						uni.hideLoading()
						this.showToast(res, () => {
							this.navigate('/page_other/submit/submit')
						})
					}).catch((res) => {
						uni.hideLoading()
						this.showToast('提交失败');
					})
				}
			}

		},
		onLoad() {
		},
		onReachBottom() {
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fafafa;
	}
	.swiper-block {
		width: 100%;
		height: 280rpx;
		box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
		border-radius: 20rpx;
		.img{
			width: 100%;
			height: 100%;
		}
	}
	.content {
		width: 100%;
		padding: 30rpx;
		.step{
			width: 350rpx;
			height: 100rpx;
			display: flex;
			background-color: red;
			color: #fff;
			margin: 30rpx auto;
			border-radius: 60rpx;
			justify-content: center;
			align-items: center;
		}
		.menu-block {
			margin-top: 30rpx;
			background: #fff;
			border-radius: 12px;
			padding: 30rpx;
			.form-title {
				font-size: 36rpx;
				font-weight: bold;
			}
			
			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;
			
				.form-label {
					font-size: 28rpx;
					color: #999;
				}
			
				.form-content {
					display: flex;
					flex-direction: row;
					align-items: center;
			
					.form-ctrl {
						height: 100rpx;
						line-height: 100rpx;
						flex-grow: 1;
					}
			
					.arrow {
						flex-grow: 0;
						color: #999;
						font-size: 24rpx;
					}
				}
			}
			.title{
				font-weight: 900;
				font-size: 30rpx;
				line-height: 60rpx;
				width: 80%;
				overflow: hidden; 
				white-space: nowrap; 
				text-overflow: ellipsis;
			}
		}
	}
</style>